home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000030_icon-group-sender _Sun Jan 23 10:35:09 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
4KB
Received: by cheltenham.cs.arizona.edu; Sun, 30 Jan 1994 20:22:17 MST
Date: 23 Jan 94 10:35:09 GMT
From: noc.near.net!news.delphi.com!usenet@uunet.uu.net (Will Mengarini)
Organization: Delphi Internet
Subject: MS-DOS drive/dir query routines
Message-Id: <940123.20109.MENGARINI@delphi.com>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: RO
Errors-To: icon-group-errors@cs.arizona.edu
I suggest the Icon Project incorporate this in BIPL.
-------------------------------<CUT HERE (duh)>------------------------------
############################################################################
#
# File: drivedir.icn
#
# Subject: Procedures to inquire MS-DOS working dirs & current drive
#
# Author: Will Mengarini
#
# Date: Sa 18 Sep 93
#
############################################################################
#
# Requires: MS-DOS, DR-DOS, or compatible system
#
############################################################################
#
# Every disk drive on a MS-DOS system has a "working directory", which is
# the directory referred to by any references to that drive that don't begin
# with a backslash (& so are either direct references to that working
# directory, or paths relative to it). There is also 1 "current drive", &
# its working directory is called the "current working directory". Any paths
# that don't explicitly specify a drive refer to the current drive. For
# example, "name.ext" refers to the current drive's working directory, aka
# the current working directory; "\name.ext" refers to the current drive's
# root directory; & "d:name.ext" refers to the working directory on d:.
#
# It's reasonable to want to inquire any of these values. The CD command
# displays both, in the form of a complete path to the current working
# directory. However, passing such a path to either CD or the Icon function
# chdir() doesn't change to that dir on that drive; it changes that drive's
# working directory to the specified path without changing the current
# drive. The command to change the current drive is the system() function
# of a command consisting of just the drive letter followed by ":".
#
# This affects the design of inquiry functions. They could be implemented
# with system( "CD >" || ( name := tempname() ) ) & read(open(name)), but
# because this requires a slow disk access (which could fail on a full disk)
# it's unacceptable to need to do that *twice*, once for the drive & again
# for the dir; so if that strategy were used, it'd be necessary to return a
# structure containing the current drive & the working directory. That
# structure, whether table, list, or string, would then need to be either
# indexed or string-scanned to get the individual values, making the code
# cumbersome & obscure. It's much better to have 2 separate inquiry
# functions, 1 for each value; but for this to be acceptably efficient, it's
# necessary to forgo the disk access & implement the functions with
# interrupts.
#
# getdrive() returns the current drive as a lowercase string with the ":".
# getwd("g") and getwd("g:") return the working directory on drive g:, or
# fail if g: doesn't exist. getwd() returns the current working directory.
# getwd(...) always returns lowercase. It prepends the relevant drive letter
# with its colon; that's harmless in a chdir(), & useful in an open().
#
############################################################################
procedure getdrive()
return &lcase[iand( Int86([33,16r1900,0,0,0,0,0,0,0])[2], 255 )+1] || ":"
end
procedure getwd(drive)
A := GetSpace(64) | stop( "getwd(): GetSpace() failed." )
dx := ("36r" || !\drive) - 9 | 0
si := iand( A, 16rffff ); ds := ishift( A, -16 )
cf := !Int86([33,16r4700,0,0,dx,si,0,0,ds]) % 2
Peek( A , 64 ) ? path := tab(many(~'\0')) | ""
FreeSpace(A)
cf = 0 | fail
return ( map(!\drive) || ":" | getdrive() ) || "\\" || map(path)
end
-------------------------------<CUT HERE (duh)>------------------------------